home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11112 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: snail.stack.urc.tue.nl!not-for-mail
  2. From: pascalz@stack.urc.tue.nl (Pascal Zinken)
  3. Newsgroups: comp.lang.c
  4. Subject: How to expand printf()?
  5. Date: 22 Mar 1996 01:27:28 +0100
  6. Organization: MCGV Stack, Eindhoven University of Technology, the Netherlands.
  7. Message-ID: <4iss5g$2av@snail.stack.urc.tue.nl>
  8. NNTP-Posting-Host: snail.stack.urc.tue.nl
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Well... As the subject said... I am currently seeking a nice (and as
  12. portable as possible) way to expand the function printf(). I want to
  13. insert some new tokens, namely something like %C for changing the color
  14. of the text.
  15.  
  16. This could be done by 'simply' writing my own printf(). But i really don't
  17. feel like that.
  18.  
  19. Then i got to the part i thought of the following, though i am not sure if
  20. it would work because i do not yet fully understand the way stdarg works.
  21. I would examine the format string:
  22.  
  23. char *pcFormat; /* Given as parameter. */
  24. if ( IsNormalFormatSpecifier( &pcFormat[ nCurrentPosition]))
  25.    vprintf( pcBuffer, &pcFormat[ nCurrentPosition], pArg);
  26. else
  27.    UseOwnRoutineToFillpcBuffer();
  28.  
  29. pArg is then a va_list variable. But, then, i am not sure if calling
  30. vprintf() a multiple number of times will do exactly what i want.
  31.  
  32. For example, if i had the following string...
  33.  
  34. "printing %d characters in %Ccolor resulted in %d", with the additional
  35. parameters 200, WHITE (or something like that) and 42, would
  36. calling vprintf(), OwnRoutine, vprintf() in that order do the trick?
  37.  
  38. Please... i've had my time reading the FAQ-list, examined a number of books
  39. on handling a variable parameter count, but did not yet find out the answer.
  40.  
  41. Oh, before i forget, i do know how to handle a variable number of arguments.
  42. I only do not know how to expand printf() without rewriting it from scratch.
  43. I just want the original printf() to handle the normal formats, and my own
  44. routine to handle my ones.
  45.  
  46. Please... help me out..
  47. Send any usefull replies to either balls@cpc.nl or to
  48. pascalz@stack.urc.tue.nl
  49.  
  50. though the latter one goes down too often on my account!
  51.  
  52. Greetings, and thanx, Pascal Zinken
  53.